using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using MacomberMap.Common.Components;
using System.Windows.Forms;

namespace MacomberMap.Common.Events
{
    /// <summary>
    /// This class handles items not being found
    /// </summary>
    public class MM_Event_ItemNotFound: MM_Event
    {
        #region Variable declarations

        /// <summary>
        /// The object that was searched for
        /// </summary>
        public String SearchedObject;

        /// <summary>
        /// The target of the search
        /// </summary>
        public MemberInfo TargetInfo;

        /// <summary>
        /// The base element for the item
        /// </summary>
        public Object BaseElement;

        /// <summary>
        /// The target value of the query
        /// </summary>
        public Object TargetValue;
        #endregion

        #region Initialization
        /// <summary>
        /// Initialize a new not found event
        /// </summary>
        /// <param name="BaseElement"></param>
        /// <param name="SearchedObject"></param>
        /// <param name="TargetInfo"></param>
        /// <param name="TargetValue"></param>
        public MM_Event_ItemNotFound(Object BaseElement, String SearchedObject, MemberInfo TargetInfo, Object TargetValue)
        {
            this.BaseElement = BaseElement;
            this.TargetInfo = TargetInfo;
            this.SearchedObject = SearchedObject;
            this.TargetValue = TargetValue;
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="OutMenu"></param>
        public override void AddMenuItems(System.Windows.Forms.ContextMenuStrip OutMenu)
        {
         
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ListViewItem BuildListViewItem()
        {
            ListViewItem OutItem = new ListViewItem(BaseElement.ToString());
            OutItem.SubItems.Add(EventState.ToString());
            OutItem.SubItems.Add(TimeText);
            OutItem.ImageIndex = this.EventType.Index;
            return OutItem;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="OutParent"></param>
        public override void DisplayDetails(System.Windows.Forms.Control OutParent)
        {
            TreeView tvOut = new TreeView();
            tvOut.Dock = DockStyle.Fill;
            this.AddNodeItem("Element", BaseElement, tvOut.Nodes);
            this.AddNodeItem("Searched Object", SearchedObject, tvOut.Nodes);
            this.AddNodeItem("Target Info", TargetInfo, tvOut.Nodes);
            this.AddNodeItem("Target Value", TargetValue, tvOut.Nodes);
            tvOut.Nodes[0].EnsureVisible();
            OutParent.Controls.Add(tvOut);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lvItem"></param>
        public override void UpdateListViewItem(ListViewItem lvItem)
        {
            lvItem.SubItems[0].Text = BaseElement.ToString();
            lvItem.SubItems[1].Text = EventState.ToString();
            lvItem.SubItems[2].Text = TimeText;
        }

        /// <summary>
        /// Compare two item not found errors
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override int CompareTo(object obj)
        {
            return SearchedObject.CompareTo((obj as MM_Event_ItemNotFound).SearchedObject);
        }
    }
}
